<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class TestController extends Controller
{
    //
    public function captcha(){

        return view('captcha');

    }
    public function checkCaptcha(Request $request)
    {
        $this->validate($request, [
            'captcha' => 'required|captcha'
        ], [
            'captcha.captcha' => '验证码有误'
        ]);
       // return '验证成功';//
       return redirect()->route('home');

    }
    public function cache()
    {
     //   Cache::put('name','张三');
   //     Cache::put('name','李四');
  //    Cache::add('age','6');
       // Cache::add('age','16');//
       //$value= Cache::get('name','d');
     //  $value= Cache::get('age');
      // dump($value);
      // if (Cache::has('name')) {
      //  # code...
     //   dump('存在');
    //   }else{
    //    dump('不存在');
   //    }
 //  $value=Cache::pull('age');
//   dump($value);
   //  Cache::flush();    
     cache::add('count',0,1000);
     Cache::increment('count',10);
     Cache::decrement('count',10);
     return '你是第'. Cache::get('count'). '位访客';
    }       
//public function testarr()
//{
  //  $array=Arr::add(['name'=>'tom'],'age',18);
   // Arr::get($array,'name');
   // Arr::get($arr,'emali','adlerian@adlerian.xyz');
   // $arr=Arr::except($arr, ['emali']);
   // dump($arr); 
//}
public function testArr()
{
    $arr = ['Desk','Table','Chair'];
    $sorted = Arr::sort($array);
    $num = [100,300,200];
    $numsorted = Arr::sort($num);
}
public function teststr()
{
    // $value=Str::camel('foot_bar');
    // $value=Str::kebab('footBar');
    // $value=Str::snake('footBar');
$value = Str::is('foot*', 'footBar');
$value1 = Str::is('foot*', 'footBar');

dump($value);
dump($value1);
}
public function testURL()
{
    // $url = action('Testcontroller@form');
    // $url1 = action('Testcontroller@from', ['id' => 1]);
    $url2 = route('home');
    // 生成结果: http://localhost/img/photo.jpg
    $url3 = asset('img/photo.jpg');
    //dump($url);
    // dump($url1);
    dump($url2);
    dump($url3);
}
public function testpath()
{
    $path = app_path();
    $path1 = base_path();
    dump($path);
    dump($path1);
}
public function xmldata()
{
$xml=new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><booklist></booklist>');
$book= $xml->addChild('book');
$book->addChild('name','laravel框架');
$book->addChild('name','黑马程序员');
$book= $xml->addChild('book');
$book->addChild('name','Vue3');
$book->addChild('author','黑马');
$content=$xml->asXML();
return response($content)->header('Content-Type','text/xml');
}
public function xml(){
    return view('xml');
}
public function jsondata()
{
    $data=[['id'=>'1','name'=>'普京','age'=>'61'],['id'=>'2','name'=>'拜登']]

}
public function json()
{
    return view('json');
}
}
